<?php

defined('BASEPATH') OR exit('No direct script access allowed');
/**
 *
 * @package		Adminpro
 * @author		Tran Hoang Thien (thienhb12@gmail.com)
 * @copyright   PHP TEAM
 * @link		http://phpandmysql.net
 * @since		Version 1.0
 * @phone       0944418192
 *
 */
ob_start();
class Info extends MY_Controller {

	public function __construct(){
		parent:: __construct();
		$this->load->model('film_model');
		$this->load->model('film_info_model');
		$this->load->model('episode_model');
		$this->load->model('category_model');
		$this->load->model('page_model');
		$this->load->model('config_model');
	}

	public function index(){
		$data                      = array();
		$rewrite_id 	           = $this->uri->segment(2);
		$id                        = str_replace('f','',array_pop(explode('-', $rewrite_id)));
		$param                     = array('thumb','big_thumb','viewed','content','name','country','film_year','status','duration','director','actor','keywords','description','Trailer','category','rewrite');
		$data['result']            = $this->film_model->get_info($id,$param);
		$param_film_info		   = array('tag','tags_rewrite');
		$data['result_film_info']  = $this->film_info_model->get_info($id,$param_film_info);
		$param_ep		   		   = array();
		$param_ep['select']		   = array('epid','epname','url');
		$param_ep['where']		   = array('idphim' => $id);
		$param_ep['order']         = array('epid','ASC');
		$data['result_ep']         = $this->episode_model->get_list($param_ep);
		$data['total_ep']          = count($data['result_ep']);
		$data['config']            = $this->cache_site->get_info_cache($key = 'config',$time = 86400,$this->config_model->get_config_info());
		$data['title']             = $data['result']['name'];
		$data['keywords']          = $data['result']['keywords'];
		$data['description']       = $data['result']['description'];
		$data['phone']             = $data['config']['cf_phone'];
		$data['email']             = $data['config']['cf_email'];
		$data['result_cate']       = $this->cache_site->get_info_cache($key = 'cate',$time = 86400,$this->category_model->get_data_cate());
		$data['page']              = $this->cache_site->get_info_cache($key = 'page',$time = 86400,$this->page_model->get_list_page());
		$data['ongoing']           = $this->cache_site->get_info_cache($key = 'ongoing',$time = 1800,$this->film_model->film_new(30));
		$data['category_name']	   = array();	
		$data['category_rewrite']  = array();	
		if(!empty($data['result']['category'])){
			foreach ($data['result_cate'] as $value) {
				$data['category_name'][$value['idcate']]    = $value['namecate'];
				$data['category_rewrite'][$value['idcate']] = $value['rewrite'];	
			}
		}
		$arr_tag         		   = explode(',', $data['result_film_info']['tag']);
		$arr_tag_rewrite           = explode(',', $data['result_film_info']['tags_rewrite']);
		$arr_data                  = array();
		
		if(!empty($arr_tag)){
			foreach ($arr_tag as $key => $value) {
			 	$arr_data[$key]['tag'] = $value;
			} 
		}

		if(!empty($arr_tag_rewrite)){
			foreach ($arr_tag_rewrite as $key => $value) {
			 	$arr_data[$key]['tag_rewrite'] = $value;
			} 
		}
		$data['result_tag']		   = $arr_data;    	
		$data['sidebar']           = 'side_ongoing';
		$data['template']          = 'film/info';
		$this->load->view("layout",$data);
	}

}
ob_flush();
/* End of file index.php */
/* Location: ./application/modules/home/controllers/index.php */